<template>
  <a-layout class="context_article">

    <a-layout-sider v-model:collapsed="collapsed" :trigger="null" collapsible>
      <a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline">
        <a-menu-item key="1">
          <user-outlined />
          <span>文章管理</span>
        </a-menu-item>
        <a-menu-item key="2">
          <video-camera-outlined />
          <span>标签管理</span>
        </a-menu-item>
        <a-menu-item key="3">
          <upload-outlined />
          <span>用户管理</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>

    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="toggleCollapse"
        />
        <menu-fold-outlined v-else class="trigger" @click="toggleCollapse" />
      </a-layout-header>

      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }"
      >
        <div v-if="currentSelectedKey === '1'">
          <articleContents/>
        </div>
        <div v-else-if="currentSelectedKey === '2'">
         <tally/>
        </div>
        <div v-else-if="currentSelectedKey === '3'">
         <userControl/>
        </div>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue';
import articleContents from '@/components/articleContents.vue'
import tally from '@/components/tally.vue'
import userControl from '@/components/userControl.vue'
import {
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
  MenuUnfoldOutlined,
  MenuFoldOutlined,
} from '@ant-design/icons-vue';

const selectedKeys = ref<string[]>(['1']); 
const collapsed = ref(false);
const currentSelectedKey = ref('1'); 


watch(selectedKeys, (newVal) => {
  currentSelectedKey.value = newVal[0]; 
});

const toggleCollapse = () => {
  collapsed.value = !collapsed.value;
};
</script>

<style scoped>
.context_article {
  height: 80vh;
}

.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

.trigger:hover {
  color: #1890ff;
}

.site-layout .site-layout-background {
  background: #fff;
}
</style>
